package demo_09_27_06;

import java.util.Arrays;
import java.util.Scanner;

import class_01.demo_01;
/**
 * @author:连志鹏
 * @className:work_01
 * @descrption:
 * @date: 2021/9/26 20:07
 * @version: 0.1
 * @since: 1.8
 */


//人机猜拳
public class work_01 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("---------欢迎---------");
        System.out.println("*********开始*********");
        System.out.println("----------------------");
        System.out.println("出拳规则：1.剪刀 2.石头 3.布");
        System.out.print("请输入对方角色：1.刘备,2.孙权,3,曹操");
        user us = new user();
        computer com = new computer();

        int n = sc.nextInt();
        switch (n){
            case 1:
                com.setName("刘备");
                break;
            case 2:
                com.setName("孙权");
                break;
            case 3:
                com.setName("曹操");
                break;
        }
        com.setRet(0);com.setFrequency(0);

        System.out.print("请输入你的姓名");
        String name = sc.next();
        us.setFrequency(0);us.setName(name);us.setRet(0);
        game ga = new game();
        System.out.println("开始吗？y or n");
        String str = sc.next();
        if(str.equals("y"))
        {
            ga.initial(us,com);
            ga.gameStar(us,com);
        }else
            return;

    }

}

class game{

    public game(){};
    public game(user user1, computer com) {
        this.user1 = user1;
        this.com = com;
    }
    public void gameStar(user user1,computer com)
    {
        Scanner sc = new Scanner(System.in);
        String ret = null;
        int pun1 = 0;
        int pun2 = 0;
        do {
            System.out.print("请出拳：");
            pun1 = sc.nextInt();
            pun2 = com.punches();
            int con = judgeOutcome(pun1,pun2);
            if(con==1)
            {
                System.out.println("你获胜");
                user1.setRet(user1.getRet()+1);
            }
            else if (con==-1)
            {
                System.out.println(com.getName()+"获胜");
                com.setRet(com.getRet()+1);
            }else
                System.out.println("平局");
            System.out.println("你出的是"+pun1+"机器出的是"+pun2);
            System.out.println("是否开启下一轮？ y or n");
            ret = sc.next();

        }while (ret.equals("y"));
        if(user1.getRet()>com.getRet())
            System.out.println("你赢了");
        else if(user1.getRet()<com.getRet())
            System.out.println("你输了");
        else
            System.out.println("平局");

        sc.close();
    }
    public int judgeOutcome(int a,int b){
        if((a==1)&&(b==2))
            return -1;
        if((a==1)&&(b==3))
            return 1;
        if((a==2)&&(b==1))
            return 1;
        if((a==2)&&(b==3))
            return -1;
        if((a==3)&&(b==1))
            return -1;
        if((a==3)&&(b==2))
            return 1;
        else
            return 0;
    }

    public void initial(user u,computer c)
    {
        this.com = c;
        this.user1 = u;
    }

    public user getUser1() {
        return user1;
    }

    public void setUser1(user user1) {
        this.user1 = user1;
    }

    public computer getCom() {
        return com;
    }

    public void setCom(computer com) {
        this.com = com;
    }

    private user user1;
    private computer com;


}





class computer {
    public computer(){};

    demo_01 demo = new demo_01();
    public int punches(){
        int num = demo.random_01(1,4);
        this.setRet(num);
        return num;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getFrequency() {
        return frequency;
    }

    public void setFrequency(int frequency) {
        this.frequency = frequency;
    }


    public computer(String name, int frequency, int ret) {
        this.name = name;
        this.frequency = frequency;
        this.ret = ret;
    }

    private String name;
    private int frequency;
    private int ret;

    public int getRet() {
        return ret;
    }

    public void setRet(int ret) {
        this.ret = ret;
    }
}

class user extends computer{
    public user(){}

    public user(String name, int frequency, int ret) {
        super(name, frequency, ret);
    }

}

